package lg.minecraft.plugin.cobblemoncore.config.mapping;

import com.cobblemon.mod.common.api.types.ElementalType;
import com.cobblemon.mod.common.api.types.ElementalTypes;
import lg.minecraft.plugin.cobblemoncore.LGCobblemonCore;
import lombok.Getter;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class ElementalTypeMapping extends AbstractMapping<ElementalType> {

    public ElementalTypeMapping() {
        super(LGCobblemonCore.getInstance(), "elemental_type.yml", LGCobblemonCore.getMappingDirectory().getPath());
    }

    @Override
    protected boolean isUseLocalFile() {
        return LGCobblemonCore.getMainConfig().isElementalType();
    }

    @Override
    protected void loadFromDynamicSource() {
        for (ElementalType type : ElementalTypes.INSTANCE.all()) {
            String displayName = type.getDisplayName().getString();
            set(type.getName(), displayName);
            mapping.put(displayName, type);
            reverse.put(type, displayName);
        }
    }

    @Override
    protected void loadFromLocalFile() {
        for (String key : getKeys(false)) {
            String value = getString(key);
            ElementalType type = ElementalTypes.INSTANCE.get(key);
            if (type == null) {
                getPlugin().getLogger().warning("Elemental Type " + key + " not found!");
                continue;
            }
            mapping.put(value, type);
            reverse.put(type, value);
        }
    }

}
